const app = getApp();

Page({
  data: {
    orders: []
  },

  onShow() {
    this.loadOrders();
  },

  async loadOrders() {
    try {
      const res = await wx.request({
        url: `${app.globalData.baseUrl}/order/`,
        method: 'GET',
        header: {
          'Authorization': `Bearer ${wx.getStorageSync('token')}`
        }
      });

      if (res.data.code === 200) {
        this.setData({
          orders: res.data.data
        });
      }
    } catch (error) {
      wx.showToast({
        title: '加载订单失败',
        icon: 'none'
      });
    }
  },

  handleOrderDetail(e) {
    const { id } = e.currentTarget.dataset;
    wx.navigateTo({
      url: `/pages/order/detail/detail?id=${id}`
    });
  }
}); 